<?php
/**
 * 秒杀商品查询接口【申请】 jd.union.open.goods.seckill.query
 *
 * See: https://union.jd.com/openplatform/api/667
 * User: Ken.Zhang <kenphp@yeah.net>
 * Date: 2019-05-12
 */
class UnionOpenGoodsSeckillQueryRequest {

    /**
     * sku id集合，长度30。如果传值，忽略其他查询条件
     */
    private $skuIds;

    /**
     * 页码，默认1
     */
    private $pageIndex;

    /**
     * 每页数量最大30，默认30
     */
    private $pageSize;

    /**
     * 是否返回未开始秒杀商品。1=返回，0=不返回
     */
    private $isBeginSecKill;

    /**
     * 秒杀价区间开始（单位：元）
     */
    private $secKillPriceFrom;

    /**
     * 秒杀价区间结束
     */
    private $secKillPriceTo;

    /**
     * 一级类目
     */
    private $cid1;

    /**
     * 二级类目
     */
    private $cid2;

    /**
     * 三级类目
     */
    private $cid3;

    /**
     * g=自营，p=pop
     */
    private $owner;

    /**
     * 佣金比例区间开始
     */
    private $commissionShareFrom;

    /**
     * 佣金比例区间结束
     */
    private $commissionShareTo;

    /**
     * 排序字段，默认搜索综合排序。
     * 允许的排序字段：stuPrice、commissionShare、inOrderCount30Days、inOrderComm30Days
     */
    private $sortName;

    /**
     * desc=降序，asc=升序，可为空（默认降序）
     */
    private $sort;

    /**
     * 请求参数
     */
    public $apiParams = [];

    public function setSkuIds($sku_ids)
    {
        $this->skuIds = $sku_ids;
        $this->apiParams['goodsReq']['skuIds'] = $sku_ids;
    }

    public function getSkuIds()
    {
        return $this->skuIds;
    }

    public function setPageIndex($page_index)
    {
        $this->pageIndex = $page_index;
        $this->apiParams['goodsReq']['pageIndex'] = $page_index;
    }

    public function getPageIndex()
    {
        return $this->pageIndex;
    }

    public function setPageSize($page_size)
    {
        $this->pageSize = $page_size;
        $this->apiParams['goodsReq']['pageSize'] = $page_size;
    }

    public function getPageSize()
    {
        return $this->pageSize;
    }

    public function setIsBeginSecKill($is_begin_sec_kill)
    {
        $this->isBeginSecKill = $is_begin_sec_kill;
        $this->apiParams['goodsReq']['isBeginSecKill'] = $is_begin_sec_kill;
    }

    public function getIsBeginSecKill()
    {
        return $this->isBeginSecKill;
    }

    public function setSecKillPriceFrom($sec_kill_price_from)
    {
        $this->secKillPriceFrom = $sec_kill_price_from;
        $this->apiParams['goodsReq']['secKillPriceFrom'] = $sec_kill_price_from;
    }

    public function getSecKillPriceFrom()
    {
        return $this->secKillPriceFrom;
    }

    public function setSecKillPriceTo($sec_kill_price_to)
    {
        $this->secKillPriceTo = $sec_kill_price_to;
        $this->apiParams['goodsReq']['secKillPriceTo'] = $sec_kill_price_to;
    }

    public function getSecKillPriceTo()
    {
        return $this->secKillPriceTo;
    }

    public function setCid1($cid1)
    {
        $this->cid1 = $cid1;
        $this->apiParams['goodsReq']['cid1'] = $cid1;
    }

    public function getCid1()
    {
        return $this->cid1;
    }

    public function setCid2($cid2)
    {
        $this->cid2 = $cid2;
        $this->apiParams['goodsReq']['cid2'] = $cid2;
    }

    public function getCid2()
    {
        return $this->cid2;
    }

    public function setCid3($cid3)
    {
        $this->cid3 = $cid3;
        $this->apiParams['goodsReq']['cid3'] = $cid3;
    }

    public function getCid3()
    {
        return $this->cid3;
    }

    public function setOwner($owner)
    {
        $this->owner = $owner;
        $this->apiParams['goodsReq']['owner'] = $owner;
    }

    public function getOwner()
    {
        return $this->owner;
    }

    public function setCommissionShareFrom($commission_share_from)
    {
        $this->commissionShareFrom = $commission_share_from;
        $this->apiParams['goodsReq']['commissionShareFrom'] = $commission_share_from;
    }

    public function getCommissionShareFrom()
    {
        return $this->commissionShareFrom;
    }

    public function setCommissionShareTo($commission_share_to)
    {
        $this->commissionShareTo = $commission_share_to;
        $this->apiParams['goodsReq']['commissionShareTo'] = $commission_share_to;
    }

    public function getCommissionShareTo()
    {
        return $this->commissionShareTo;
    }

    public function setSortName($sort_name)
    {
        $this->sortName = $sort_name;
        $this->apiParams['goodsReq']['sortName'] = $sort_name;
    }

    public function getSortName()
    {
        return $this->sortName;
    }

    public function setSort($sort)
    {
        $this->sort = $sort;
        $this->apiParams['goodsReq']['sort'] = $sort;
    }

    public function getSort()
    {
        return $this->sort;
    }

    public function getApiMethodName()
    {
        return 'jd.union.open.goods.seckill.query';
    }

    /**
     * 解析结果
     *
     * @param   string      $response
     * @throws  Exception
     * @return  mixed
     */
    public function getResult($response)
    {
        $responseKey = str_replace('.', '_', $this->getApiMethodName()) . '_response';

        $response = @json_decode($response, true);
        if (!array_key_exists($responseKey, $response))
            $resp = $response['errorResponse'];
        else {
            $response[$responseKey]['result'] = json_decode($response[$responseKey]['result']);

            $resp = $response[$responseKey];
        }

        return $resp;
    }

}